package Model;

import DAO.InterfaceDAO.CompteDAO;
import DAO.InterfaceDAO.EtudiantDAO;
import DAO.InterfaceDAO.ProfesseurDAO;
import Factories.FactoryDAO;

public class Compte {

	protected int idCompte;
	protected String login;
	protected String motDePasse;
	protected String nom;
	protected String prenom;
	protected boolean active=false;

	protected CompteDAO codao;
	protected EtudiantDAO edao;
	protected ProfesseurDAO pdao;

	public Compte connexion() {
		return codao.read(this.login, this.motDePasse);		
	}

	public boolean deconnexion() {
		boolean etat=false;
		if(isActive())
		{etat=true;}
		return etat;
	}

	public Compte(int idCompte, String login, String motDePasse, String nom, String prenom) {
		this.idCompte = idCompte;
		this.login = login;
		this.motDePasse = motDePasse;
		this.nom = nom;
		this.prenom = prenom;
		this.codao=FactoryDAO.getInstance(null).createCompteDAO();
		this.pdao= FactoryDAO.getInstance(null).createProfDAO();
		this.edao=FactoryDAO.getInstance(null).createEtudDAO();
	}

	public boolean exist() {
		if (codao.exist(this.login, this.motDePasse)) {		
			this.idCompte = codao.getId(this.login, this.motDePasse);
			return true;
		}
		return false;
	}

	public boolean isEtudiant() {
		return codao.isEtudiant(this.idCompte,this.login,this.motDePasse);
	}

	public boolean isProf() {
		return codao.isProf(this.idCompte,this.login,this.motDePasse);
	}

	public boolean isAdmin() {
		return codao.isAdmin(this.idCompte,this.login,this.motDePasse);
	}

	public Compte(){
		this.codao=FactoryDAO.getInstance(null).createCompteDAO();
	}

	public int getIdCompte() {

		return idCompte;
	}

	public void setIdCompte(int idCompte) {
		this.idCompte = idCompte;
	}

	public String getLogin() {
		return login;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	public String getMotDePasse() {
		return motDePasse;
	}

	public void setMotDePasse(String motDePasse) {
		this.motDePasse = motDePasse;
	}

	public void changerMotDePasse(String mdp) {
		this.motDePasse = mdp;
	}

	public String getNom() {
		return nom;
	}

	public void setNom(String nom) {
		this.nom = nom;
	}

	public String getPrenom() {
		return prenom;
	}

	public void setPrenom(String prenom) {
		this.prenom = prenom;
	}

	public boolean isActive() {
		return active;
	}

	public void setActive(boolean active) {
		this.active = active;
	}

}
